package org.space.galaxyCabinet.handler.impl;

import com.alibaba.fastjson2.JSON;
import com.alibaba.fastjson2.JSONObject;
import org.space.galaxyCabinet.constant.EmqxConstants;
import org.space.galaxyCabinet.handler.MassageHandler;
import lombok.extern.slf4j.Slf4j;
import org.space.galaxyCabinet.annotation.GuiguEmqx;
import org.space.galaxyCabinet.clients.OrderClients;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

@Slf4j
@Component
@GuiguEmqx(topic = EmqxConstants.DEVICE_ALL_GENERATE_ORDER)
public class GenerateOrderHandler implements MassageHandler {

    @Autowired
    private OrderClients orderClients;

    @Override
    public void handleMessage(JSONObject message) {
        log.info("开始处理属性上报消息...");
        try {
            // 检查消息是否为空
            if (message == null || message.isEmpty()) {
                log.warn("收到空消息");
                return;
            }
            String powerBankNo = message.getString("");

            orderClients.updateStatus(JSON.parseObject(JSON.toJSONString(message), OrderClients.class));
            log.info("msg:{}", powerBankNo);
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
}
